const {
    baseUrl
} = require('./env.js').role
const Names = 'zmy' //个人域名
module.exports = {
        // 把要封装的属性名当做参数传进函数
    request: (url, method, data, Vip = true) => {
        let URL = `${baseUrl}${Names}${url}`
        if (Vip == true) {
            URL = `${baseUrl}/${Names}/${url}`
            // console.log(URL);
        } else {
            URL = `${baseUrl}${url}`
        }
        return new Promise((resolve, reject) => {
            // wx.showLoading({
            //     title:'正在玩命加载中。。。',
            //     mask:true,
            // })            
            wx.request({
                url: URL,
                method: method,
                data: data,
                header: {
                    "content-type": ' application/x-www-form-urlencoded '
                },
                success: (res) => {

                    let {
                        code
                    } = res.data
                    if (code == 0) {
                        resolve(res.data.data)
                        wx.hideLoading()
                    }else{
                        resolve(res.data)
                    }
                },
                fail: (error) => {
                    reject(error)
                }

            })
        })
    }
}